import 'package:flutter/material.dart';

void main() {
  runApp(
    const MaterialApp(
      home: Main(),
    ),
  );
}

class Main extends StatelessWidget {
  const Main({super.key});
  static const List myList = [
    {
      'name': '张三',
      'age': 18,
      'color': Colors.red,
    },
    {
      'name': '李四',
      'age': 19,
      'color': Colors.yellow,
    },
    {
      'name': '王五',
      'age': 20,
      'color': Colors.green,
    },
    {
      'name': '赵六',
      'age': 21,
      'color': Colors.orange,
    },
    {
      'name': '钱七',
      'age': 22,
      'color': Colors.purple,
    },
    {
      'name': '孙八',
      'age': 23,
      'color': Colors.teal,
    },
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.amber,
        title: const Text(
          'GirdView-渲染列表',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
      ),
      body: Container(
        padding: const EdgeInsets.all(10),
        color: Colors.black26,
        child: GridView.extent(
            maxCrossAxisExtent: 200,
            mainAxisSpacing: 10,
            crossAxisSpacing: 10,
            childAspectRatio: 100 / 50,
            // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            //   crossAxisCount: 3, // 3 列
            //   mainAxisSpacing: 10, // 主轴间距
            //   crossAxisSpacing: 10, // 侧轴间距
            //   childAspectRatio: 100 / 50, // 宽高比
            // ),
            children: myList.map(
              (item) {
                return Container(
                  color: item['color'],
                  alignment: Alignment.center,
                  child: Text('${item['name']}今年${item['age']}'),
                );
              },
            ).toList()),
      ),
    );
  }
}
